﻿using System;

namespace XiaoSe
{
    public static class DateTimeEx
    {
        /// <summary>
        /// 生成某年某月最后一天
        /// </summary>
        /// <param name="year">年</param>
        /// <param name="month">月</param>
        /// <param name="startOrEnd">0则生成1990年12月11日 00:00:00；其他则生成1990年12月11日 23:59:59</param>
        /// <returns></returns>
        public static DateTime GetLastDayOfMonth(int year, int month, int startOrEnd)
        {
            int days = DateTime.DaysInMonth(year, month);
            return startOrEnd == 0 ? Convert.ToDateTime(year + "年" + month + "月" + days + "日 00:00:00") : Convert.ToDateTime(year + "年" + month + "月" + days + "日 23:59:59");
        }
        /// <summary>
        /// 生成年月日时分秒毫秒字符串
        /// </summary>
        /// <param name="separator">分隔符</param>
        /// <returns>年月日时分秒毫秒字符串</returns>
        public static string CreateTimeString(string separator)
        {
            return DateTime.Now.Year + separator + DateTime.Now.Month + separator + DateTime.Now.Day + separator + DateTime.Now.Hour + separator + DateTime.Now.Minute + separator + DateTime.Now.Second + separator + DateTime.Now.Millisecond;
        }
    }

}
